package com.wwz.leetcode;

import org.junit.Test;

public class LeetCode165 {
    @Test
    public void test() {
        compareVersion("1.001","1.0");
    }

    public int compareVersion(String version1, String version2) {
        String[] split = version1.split("\\.");
        int length1 = split.length;
        String[] split2 = version2.split("\\.");
        int length2 = split2.length;
        int maxLength = Math.max(length1, length2);

        for (int i = 0; i < maxLength; i++) {
            int x = 0,y =0;
            if(i <length1){
                x = Integer.valueOf(split[i]);
            }
            if(i < length2){
                y = Integer.valueOf(split2[i]);
            }
            if(x > y){
                return 1;
            }else if(y > x){
                return -1;
            }

        }
        return 0;
    }
}
